# -*- coding: utf-8 -*-
# @Author: QX
# @File: day6_0062sleep.py
from time import sleep, time

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support  import expected_conditions  as EC
dis={
  "platformName": "Android",
  "appium:platformVersion": "9",
  "appium:appPackage": "com.zhao.myreader",
  "appium:appActivity": ".ui.home.MainActivity",
  "appium:deviceName": "emulator-5554",
  "appium:automationName": "UIAutomator2",
  "appium:noReset": True
}
driver = webdriver.Remote('http://127.0.0.1:4723',dis)
driver.activate_app("com.zhao.myreader")
start_time =  time()
#sleep(5)
driver.implicitly_wait(5)
#单击书城--//androidx.appcompat.app.ActionBar.Tab[@content-desc="书城"]/android.widget.TextView
driver.find_element(AppiumBy.XPATH,'//androidx.appcompat.app.ActionBar.Tab[@content-desc="书城"]/android.widget.TextView').click()
#单击放大镜--id  com.zhao.myreader:id/iv_search
driver.find_element(AppiumBy.ID,'com.zhao.myreader:id/iv_search').click()
#单击清空历史记录--清空历史记录
#方法1：
# ele = WebDriverWait(driver,10,1).until(EC.presence_of_element_located((AppiumBy.ANDROID_UIAUTOMATOR,'new UiSelector().text("清空历史记录")')))
# ele.click()

#方法2
# AB=(AppiumBy.ANDROID_UIAUTOMATOR,'new UiSelector().text("清空历史记录")')
# ele = WebDriverWait(driver,10,1).until(EC.presence_of_element_located(AB))
# ele.click()

#方法3
ele = WebDriverWait(driver,10,1).until(lambda x: x.find_element(AppiumBy.ANDROID_UIAUTOMATOR,'new UiSelector().text("清空历史记录")'))
ele.click()

#driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR,'new UiSelector().text("清空历史记录")').click()
#输入框定位--id com.zhao.myreader:id/et_search_key
driver.find_element(AppiumBy.ID,'com.zhao.myreader:id/et_search_key').send_keys('九重华锦')
#单击搜索按钮--id   com.zhao.myreader:id/tv_search_conform
driver.find_element(AppiumBy.ID,'com.zhao.myreader:id/tv_search_conform').click()

end_time =  time()
print('执行时间：',end_time - start_time)
driver.quit()